package com.mocha.bss.minio.controller;

import com.coffee.core.CoffeeResponse;
import com.mocha.bss.minio.service.FileService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhangtao
 * @since 2025-04-29
 */
@Slf4j
@RestController
@RequestMapping("/file")
@AllArgsConstructor
public class FileController {

    private final FileService fileService;

    /**
     * 上传文件 返回路径
     * @param file
     * @return
     */
    @PostMapping("/upload-img")
    public CoffeeResponse<String> upload(@RequestParam("file")MultipartFile file ,@RequestParam(value = "bucket",required = false) String bucket) throws Exception {
        String url = fileService.upload(file,bucket);
        return CoffeeResponse.responseSuccess(url);
    }

}
